﻿using mds.BaseFrameModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mds.ConfigurationService
{
    public class RemoteConfigureServiceProvider : IRemoteConfigureServiceProvider
    {
        public OperationResult<SoulationContainer> GetNewSoulation(Guid configId, Guid appId)
        {
            var r = new OperationResult<SoulationContainer>(false);
            var IService = ConfigurationServiceAdapter.GetService();
            var soluationResult = IService.GetSolution(configId);
            if (soluationResult.ActionResult) {
                if (soluationResult.Data.AppId != appId) {
                    r.Message = "非授权程序";
                    return r; }
                var mds = IService.GetMdsConfigureInfos(int.MaxValue, 1, string.Empty, configId);
                if (mds.ActionResult)
                {
                    r.Data = new SoulationContainer() { 
                     DetailConfig=mds.List,
                      Soluation=soluationResult.Data
                    };
                    r.ActionResult = true;
                }
            } 
            return r;
        }

        public OperationResult<SoulationContainer> GetSoulation(Guid configId, Guid appId, int version)
        {
            var r = new OperationResult<SoulationContainer>(false);
            var IService = ConfigurationServiceAdapter.GetService();
            var soluationResult = IService.GetSolution(configId);
            if (soluationResult.ActionResult)
            {
                if (soluationResult.Data.AppId != appId)
                {
                    r.Message = "非授权程序";
                    return r;
                }
                var mds = IService.GetMdsConfigureInfos(configId, version);
                if (mds.ActionResult)
                {
                    r.Data = new SoulationContainer()
                    {
                        DetailConfig = mds.Data,
                        Soluation = soluationResult.Data
                    };
                    r.ActionResult = true;
                }
            }
            return r;
        }

       
    }
}
